#include <stdlib.h>
#include "Utils.hxx"
#include "Shape.hxx"

Shape::Shape()
{
}

ShapeRect::ShapeRect(double x, double y, double w, double h)
{
    _shapeType = SHAPE_RECT;
    _rect = cv::Rect2d(x, y, w, h);
}

ShapeRect::ShapeRect(cv::Rect2d rect)
{
    _shapeType = SHAPE_RECT;
    setRect(rect);
}

ShapeFish::ShapeFish(double x, double y, double w, double h, double hx, double hy, double mx, double my):ShapeRect(x,y,w,h)
{
    _shapeType = SHAPE_FISH;
    _sfsStatus = SFS_NONE;
    _headCenter = cv::Point2d(hx, hy);
    _massCenter = cv::Point2d(mx, my);
}

ShapeFish::ShapeFish(cv::Rect2d rect, cv::Point2d headCenter, cv::Point2d massCenter):ShapeRect(rect)
{
    _shapeType = SHAPE_FISH;
    _sfsStatus = SFS_NONE;
    _headCenter = headCenter;
    _massCenter = massCenter;
}

ShapeFish::ShapeFish(cv::Rect2d rect):ShapeRect(rect)
{
    _shapeType = SHAPE_FISH;
    _sfsStatus = SFS_NONE;

    _headCenter.x = rect.x + rect.width * 0.2;
    _headCenter.y = rect.y + rect.height * 0.5;

    _massCenter.x = rect.x + rect.width * 0.5;
    _massCenter.y = rect.y + rect.height * 0.5;
}

bool ShapeFish::isPointOnMassIcon(cv::Point2d pt)
{
    cv::Rect2d rect = getRect();

    float refSize = vmin(rect.width, rect.height) * FISH_ICON_RATIO;
    float refSize2 = refSize * 2.0;

    if (pt.x >= (_massCenter.x - refSize2) && pt.x <= (_massCenter.x + refSize2) &&
        pt.y >= (_massCenter.y - refSize2) && pt.y <= (_massCenter.y + refSize2))
        return true;
    else
        return false;
}

bool ShapeFish::isPointOnHeadIcon(cv::Point2d pt)
{
    cv::Rect2d rect = getRect();

    float refSize = vmin(rect.width, rect.height) * FISH_ICON_RATIO;
    float refSize2 = refSize * 2.0;

    if (pt.x >= (_headCenter.x - refSize2) && pt.x <= (_headCenter.x + refSize2) &&
        pt.y >= (_headCenter.y - refSize2) && pt.y <= (_headCenter.y + refSize2))
        return true;
    else
        return false;
}